package com.ctgu.frequence;

import com.ctgu.frequence.Utils.GetString;
import com.ctgu.frequence.step0.CountLetter;
import com.ctgu.frequence.step1.CountWord;
import com.ctgu.frequence.step1.CountWordLimitN;
import com.ctgu.frequence.step1.TraverseDir;
import com.ctgu.frequence.step1.TraverseDir2;
import com.ctgu.frequence.step2.IgnoreStopWords;
import com.ctgu.frequence.step3.CountPhrase;
import com.ctgu.frequence.step4.VerbUnite;

import java.io.*;

public class WF {

    public static void main(String[] args) throws IOException {
        for(String s:args){
            System.out.println(s);
        }
        String path = "E:\\学期学习\\大三上\\软件工程\\Gitcode\\se_test\\testFile\\one.txt";
        File file = new File(path);//创建文件对象
        String str = GetString.getString(file); //得到文件的内容

        //判断是否有动词归一化的要求
        int len = args.length;
        if(len > 1 && args[len - 1].equals("v")){
            System.out.println("已进行动词归一化");
            String ss = args[len - 1];
            File file1 = new File("E:\\学期学习\\大三上\\软件工程\\Gitcode\\se_test\\verb.txt");
            str = VerbUnite.uniteVerb(str,file);
            //处理参数个数
            len = len - 1;
        }
        if(len == 1 && args[0].equals("c")){
            System.out.println("正在统计字母出现频率:");
            CountLetter.countLetter(str);
        }else if(len == 1 && args[0].equals("f")){
            System.out.println("正在统计单词的出现次数：");
            CountWord.countWord(str);
        }else if(len == 2 && args[0].equals("d")){
            System.out.println("正在遍历指定文件夹下的文件：");
            String dir = args[1];
            TraverseDir.traverseDir(dir);
        }else if(len == 3 && args[0].equals("d") && args[1].equals("s")){
            System.out.println("正在递归遍历指定文件夹下的文件：");
            String dir = args[2];
            TraverseDir2.traverseAllFiles(dir);
        }else if(len == 2 && args[0].equals("f")){
            int n = Integer.parseInt(args[1]);
            System.out.printf("正在统计次数最多的前%d个单词：\n",n);
            CountWordLimitN.countWordLimitN(str,n);
        }else if(len == 2 && args[0].equals("x") && args[1].equals("f")){
            System.out.println("正在统计跳过停词表之后的单词：");
            IgnoreStopWords.ignoreStopWords(str);
        }else if(len == 2 && args[0].equals("p")){
            int n = Integer.parseInt(args[1]);
            System.out.printf("正在统计%d个单词的短语：\n",n);
            CountPhrase.countPhrase(str,2);
        }else {
            System.out.println("输入命令不正确,请重新输入!");
        }

    }
}
